package collection;

public class Edge<E,V> extends ANode<E> {
	
	private Vertex<V,E> v1;
	private Vertex<V,E> v2;
	
	public EdgeType type = EdgeType.DISCOVERY;
	
	public Edge(E element)
	{
		super(element);
	}
	
	public Edge(E element, Vertex<V,E> v1, Vertex<V,E> v2)
	{
		super(element);
		this.v1 = v1;
		this.v1.addEdge(this);
		this.v2 = v2;
		this.v2.addEdge(this);
	}
	
	public Edge(Vertex<V,E> v1, Vertex<V,E> v2)
	{
		this(null, v1, v2);
	}
	
	public HashSet<Vertex<V,E>> getVertices()
	{
		HashSet<Vertex<V,E>> retSet = new HashSet<Vertex<V,E>>();
		retSet.add(v1);
		retSet.add(v2);
		return retSet;
	}
	
	public boolean hasVertex(Vertex<V,E> v)
	{
		return v1==v || v2==v;
	}
	
	public Vertex<V,E> oppositeVertex(Vertex<V,E> v)
	{
		if (v1==v)
			return v2;
		else if (v2 == v)
			return v1;
		else
			throw new IllegalArgumentException("Vertetx is not contained in this edge!");
	}
	
	@Override
	public void clear()
	{
		super.clear();
		this.v1 = null;
		this.v2 = null;
	}
	
	@Override
	public String toString()
	{
		return "[" + v1.toString() + 
				(super.element==null ? " <---> ": " <- " + super.toString() + " -> ") + 
				v2.toString() + "]";
	}
	
}
